const mongoose = require('mongoose');
const typeOneModel = mongoose.model("typeOne");

const typeTwoModel = mongoose.model("typeTwo");

module.exports = {
    //获取一级分类列表
    get: async () => await typeOneModel.find(),

    //添加一级分类
    add: async ({
        typeOne, Img
    }) => {
        console.log({
            typeOne
        }, "1321312");
        return await typeOneModel.create({
            typeOne, Img
        })
    },

    //删除一级分类
    del: async ({ _id }) => {
        const typeOneId = _id
        const data = await typeTwoModel.remove({ typeOneId })
        if (data) {
            return await typeOneModel.deleteOne({ _id })
        }
    },
    //修改一级分类
    upDate: async ({ _id, typeOne }) => await typeOneModel.updateOne({ _id }, typeOne)
}